<style>
    .action-row {
        display: flex;
        flex-direction: row;
        justify-content: center;
    }

    .action-row navigator {
        color: #007aff;
        padding: 0 20px;
    }

    .oauth-row {
        display: flex;
        flex-direction: row;
        justify-content: center;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
    }

    .oauth-image {
        width: 100px;
        height: 100px;
        border: 1px solid #dddddd;
        border-radius: 100px;
        margin: 0 40px;
        background-color: #ffffff;
    }

    .oauth-image image {
        width: 60px;
        height: 60px;
        margin: 20px;
    }
	.input-group .input-row{
		padding: 14upx 0;
		font-size: 30upx;
		display: flex;
	}
	.input-group .input-row .title{
		display: flex;
		width: auto;
	}
	.input-group .input-row input{
		display: flex;
		flex: 1;
	}
</style>
<template>
		<view class="content">
		    <view class="input-group">
		        <view class="input-row border">
		            <text class="title">新密码：</text>
		            <input type="text" password="true" v-model="password" placeholder="请输入新密码">
		        </view>
		        <view class="input-row">
		            <text class="title">确认密码：</text>
		            <input type="text" password="true" v-model="passwordTemp" placeholder="请确认密码">
		        </view>
		    </view>
		    <view class="btn-row">
		        <button type="primary" class="primary" @tap="changePwd">确认修改</button>
		    </view>
		</view>
</template>

<script>
	import {
	    mapState,
	    mapMutations
	} from 'vuex'
	
	export default {
		data() {
			return {
				password:'',
				passwordTemp:''
			};
		},
		computed: {
		    ...mapState(['userInfo'])
		},
		methods:{
			changePwd(){
				let that = this
				if(!this.password){
					uni.showToast({
						icon:'none',
						mask:true,
						title:'请填写新密码'
					})
					return
				}
				if(!this.passwordTemp ){
					uni.showToast({
						icon:'none',
						mask:true,
						title:'请确认密码'
					})
					return
				}
				if(this.password != this.passwordTemp){
					uni.showToast({
						icon:'none',
						mask:true,
						title:'两次密码不一致'
					})
					return
				}
				uni.request({
					url:that.httpUrl+'user/save',
					method:'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded' 
					},
					data:{
						uid:that.userInfo.uid,
						passwd:that.password,
					},
					success: (res) => {
					     console.log(res)
						 if(res.data.code == 1){
							 uni.showToast({
							 	title:'修改成功',
								icon:'none',
								mask:true
							 })
							 setTimeout(()=>{
								 uni.navigateBack({
								 	delta:1
								 })
							 },1000)
						 }else{
							uni.showToast({
								title:res.data.msg,
								icon:'none',
								mask:true
							}) 
						 }
					}
				})
				
			}
		}
	}
</script>
